package com.srzk.youthleagueback.service;

import com.srzk.youthleagueback.entity.po.Student;
import com.srzk.youthleagueback.entity.po.Teacher;
import com.srzk.youthleagueback.mapper.StudentMapper;
import com.srzk.youthleagueback.mapper.TeacherMapper;
import com.srzk.youthleagueback.results.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.srzk.youthleagueback.results.CodeMsg.*;

@Service
public class TeacherService {
    @Autowired
    TeacherMapper teacherMapper;

    public Result<Teacher> get(String userName) {
        Teacher teacher = teacherMapper.selectByPrimaryKey(userName);
        if(teacher==null) {
            return Result.error(NOT_EXIST);
        } else {
            return Result.success(teacher);
        }
    }

    public Result<List<Teacher>>  getList(){
        List<Teacher> user = teacherMapper.selectAll();
        if(user==null||user.isEmpty()){
            return Result.error(NOT_EXIST);
        }else{
            return Result.success(user);
        }
    }


    public Result<Teacher> update(Teacher teacher){
        int result = teacherMapper.updateByPrimaryKey(teacher);
        if (result==1){
            return Result.success(teacher);
        }else{
            return Result.error(UPDATE_FAIL);
        }
    }

   /* public Result<String> delete(String student){
        int result = teacherMapper.deleteByUsername(student);
        if(result==1){
            return Result.success("删除成功");
        }else{
            return Result.error(DELETE_FAIL);
        }
    }*/

    public Result<String> add(Teacher teacher){
        int result = teacherMapper.insert(teacher);
        if(result==1){
            return Result.success("success");
        }else{
            return Result.error(ADD_FAIL);
        }
    }
}
